import { IFeidaoAiBrowserComponent } from '@dfeidao/web/interfaces';

import set from '@dfeidao/atom-web/local/set';
import set_node_cls from '@dfeidao/atom-web/ui/set-node-cls';

interface Aa {
	id: string;
	role_no: string;
	role_name: string;
	icon: string;
	role_type_id: string;
}
export default async function a004(fd: IFeidaoAiBrowserComponent, args: Event) {
	const nodea = args.currentTarget as HTMLInputElement;

	const node = nodea.closest('[list]') as HTMLDivElement;
	const nodes = fd.data.node.querySelectorAll<HTMLDivElement>('[list]');
	nodes.forEach((i) => {
		set_node_cls(i, 'bg-c', false);
	});
	set_node_cls(node, 'bg-c', true);
	const id = nodea.getAttribute('data-feidao-id');
	const role_no = nodea.getAttribute('data-feidao-role_no');
	const role_name = nodea.getAttribute('data-feidao-role_name');
	const icon = nodea.getAttribute('data-feidao-icon');
	const role_type_id = nodea.getAttribute('data-feidao-role_type_id');
	const role_type_name = nodea.getAttribute('data-feidao-role_type_name');
	const obj = {
		id,
		role_no,
		role_name,
		icon
	} as Aa;
	if (!role_type_name) {
		obj.role_type_id = '';
	} else {
		obj.role_type_id = role_type_id;
	}
	set(fd, 'obj', obj);
}
